<html>
    <head>
        <title>OGBot</title>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <link rel="stylesheet" href="/static/layout.css" type="text/css" />
        <link rel="stylesheet" href="/static/general.css" type="text/css" />
        <script type="text/javascript" src="/static/techinfo.js"></script>
        <%
            resources = bot.handles[pid].fetchResources()
            planets = bot.handles[pid].fetchPlanets()
            activePlanet = bot.handles[pid].fetchMetadata()["planet-id"]
            
            if not request.query.p:
                abort(403)
                
            pname = ""
            if request.query.p == "resources":
                buildings = bot.handles[pid].fetchResourceBuildings()["list"].items()
                pname = "Versorgung"
            elif request.query.p == "station":
                buildings = bot.handles[pid].fetchStationBuildings()["list"].items()
                pname = "Anlagen"
            elif request.query.p == "research":
                buildings = bot.handles[pid].fetchResearch()["list"].items()
                pname = "Forschung"
            elif request.query.p == "shipyard":
                buildings = bot.handles[pid].fetchFleet()["list"].items()
                pname = "Schiffswerft"
            elif request.query.p == "defense":
                buildings = bot.handles[pid].fetchDefense()["list"].items()
                pname = "Defense"
            count = len(buildings)
            i = 0
        %>
        <script type="text/javascript">
            % for res in ("metal", "crystal", "deuterium"):
            var ${res} = {
                "actual" : ${resources[res]["resources"]["actual"]},
                "production" : ${resources[res]["resources"]["production"]}
            };
            % endfor
        </script>
        <script type="text/javascript" src="/static/resourceticker.js"></script>
        <script type="text/javascript" src="/static/queue.js"></script>
    </head>
    <body>
        <div id="container">
            <div id="header">
                <h1>
                    OGBot
                </h1>
            </div>
            <div id="navigation">
                <%include file="../tpl/mainmenu.html" />
## %>
            </div>
            <div id="content-container1">
                <div id="content-container2">
                    <div id="section-navigation">
                        <%include file="../tpl/ogame_leftmenu.html" />
## %>
                    </div>
                    <div id="content">
                        <h2>
                            ${pname}
                        </h2>
                        <p>
                            <div id="buildinfo" style="display: none">
                                <h4><span id="build-name"></span></h4>
                                % if (request.query.p == "defense" or request.query.p == "shipyard"):
                                Kosten pro St&uuml;ck (vorhanden: <span id="build-level"></span>):
                                % else:
                                Zum Ausbau auf Stufe <span id="build-level"></span> ben&ouml;tigt:<br />
                                % endif
                                <table>
                                    <tr>
                                        <td>Metall</td>
                                        <td>Kristall</td>
                                        <td>Deuterium</td>
                                        <td>Energie</td>
                                    </tr>
                                    <tr>
                                        <td id="build-metal"></td>
                                        <td id="build-crystal"></td>
                                        <td id="build-deuterium"></td>
                                        <td id="build-energy"></td>
                                    </tr>
                                    <tr>
                                        <form name="build" method="GET" action="/ajax/build">
                                            <td colspan="2">
                                                <input type="hidden" name="id" value="" />
                                                <input type="hidden" name="planet" value="${activePlanet}" />
                                                Anzahl: <input type="text" name="count" value="1" size="3" />
                                            </td>
                                            <td colspan="2" style="text-align: right"><input type="button" name="queue" value="Warteschlange" /><input type="submit" value="Bauen" /></td>
                                        </form>
                                    </tr>
                                </table>
                                Energieverbrauch: <span id="build-consumption"></span>
                            </div>
                            <table>
                                % while i < count:
                                <tr>
                                    <td><a href="#" class="getbuildinfo" id="${buildings[i][0]}"><span class="tech-name">${bot.get_tech_name(buildings[i][0])}</span> (${buildings[i][1]})</a></td>
                                    % if i+1 < count:
                                    <td><a href="#" class="getbuildinfo" id="${buildings[i+1][0]}"><span class="tech-name">${bot.get_tech_name(buildings[i+1][0])}</span> (${buildings[i+1][1]})</a></td>
                                    % if i+2 < count:
                                    <td><a href="#" class="getbuildinfo" id="${buildings[i+2][0]}"><span class="tech-name">${bot.get_tech_name(buildings[i+2][0])}</span> (${buildings[i+2][1]})</a></td>
                                    % endif
                                    % endif
                                </tr>
                                <% i += 3 %>
                                % endwhile
                            </table>
                        </p>
                    </div>
                    <div id="aside">
                        <h3>
                            Planeten
                        </h3>
                        <p>
                            <ul>
                                % for name, data in planets.items():
                                <li><a href="ajax/cp?id=${data['cp']}">${name} (${data["gal"]}:${data["sys"]}:${data["pos"]})</a></li>
                                % endfor
                            </ul>
                        </p>
                    </div>
                    <div id="footer">
                        Metall: <span id="res-metal"></span> &#124; Kristall: <span id="res-crystal"></span> &#124; Deuterium: <span id="res-deuterium"></span> &#124; Energie: ${resources["energy"]["resources"]["actualFormat"]}
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>